package com.mmm.common.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @email 1067559930@qq.com
 * @author: One
 * @date: 2023/02/04
 * @time: 10:51
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SuccessVo<T>  {
    private Integer code;
    private String msg;
    private T data;

    public SuccessVo(T t) {
        this.code = 200;
        this.msg = "成功";
        this.data = t;
    }

    public SuccessVo(String msg, T t) {
        this.code = 200;
        this.msg = msg;
        this.data = t;
    }

    public SuccessVo(Integer code, T t) {
        switch (code) {
            case 1:
                this.code = 200;
                this.msg = "增加成功";
                break;
            case 2:
                this.code = 200;
                this.msg = "删除成功";
                break;
            case 3:
                this.code = 200;
                this.msg = "修改成功";
                break;
            case 4:
                this.code = 200;
                this.msg = "查询成功";
                break;
            default:
            case 0:
                this.code = 201;
                this.msg = "操作失败";
                break;
        }

        this.data = t;
    }
    public SuccessVo(Integer code) {
        switch (code) {
            case 1:
                this.code = 200;
                this.msg = "增加成功";
                break;
            case 2:
                this.code = 200;
                this.msg = "删除成功";
                break;
            case 3:
                this.code = 200;
                this.msg = "修改成功";
                break;
            case 4:
                this.code = 200;
                this.msg = "查询成功";
                break;
            default:
            case 0:
                this.code = 201;
                this.msg = "操作失败";
                break;
        }
    }
}
